package com.dtagri.fjwlw.ui;

import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.View;

import com.dtagri.fjwlw.R;
import com.dtagri.fjwlw.base.BaseSimpleActivity;
import com.dtagri.fjwlw.broadcastreceiver.TReceiver;
import com.dtagri.fjwlw.util.TDevice;
import com.dtagri.fjwlw.viewpagerfragment.DeviceControlViewPagerFragment;

/**
 * 设备控制
 * 
 * @author wxjn
 * 
 */
public class DeviceControlActivity extends BaseSimpleActivity {

	public DeviceControlViewPagerFragment fragment;
	private View back;

	@Override
	public void initView() {
		super.initView();
		setActionBarTitle("设备控制");
		// 特别处理返回事件
		back = mActionBar.getCustomView().findViewById(R.id.btn_back);
		back.setOnClickListener(this);
	}

	@Override
	public void onClick(View arg0) {
		super.onClick(arg0);
		TReceiver.sendBroadCast(this, TReceiver.CONTROL_BACK);
		TDevice.hideSoftKeyboard(getCurrentFocus());
		onBackPressed();
	}

	@Override
	protected Fragment getFragment() {
		fragment = new DeviceControlViewPagerFragment();
		fragment.setBaseSimpleActivity((BaseSimpleActivity) this);
		return fragment;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			TReceiver.sendBroadCast(this, TReceiver.CONTROL_BACK);
			break;
		default:
			break;
		}

		return super.onKeyDown(keyCode, event);
	}
}
